package xby.study.annotations.util;

import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.AnnotatedElementUtils;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Set;

public class TestMergedAnnotationLastVersion {

    public static void main(String[] args) {


        Man animal = AnnotatedElementUtils.getMergedAnnotation(GJM.class, Man.class);
        System.out.println(animal);

        System.out.println("----------");

        /*
        * 5.26  修复了bug:  直接子类注解只有一个， 则直接分支的子类注解有多个也算一个  5.0.6
        * */

        Set<Man> animals = AnnotatedElementUtils.getAllMergedAnnotations(GJM.class, Man.class);
        System.out.println(animals.size());
        for (Man a : animals) {
            System.out.println(a);
        }

        Set<Man> animals2 = AnnotatedElementUtils.findAllMergedAnnotations(GJM.class, Man.class);
        System.out.println(animals2.size());
        for (Man a : animals2) {
            System.out.println(a);
        }



    }
}


@Jack(jackName = "CNM2")
@Ketty(kettyName = "CNM3")
@Lucy(lucyName = "CNM")
class GJM {

}


@Retention(RetentionPolicy.RUNTIME)
@Boy
@interface Jack {


    @AliasFor(annotation = Boy.class, attribute = "boyName")
    String jackName() default "jackName";

    @AliasFor(annotation = Boy.class, attribute = "boyAge")
    String jackAge() default "jackAge";

}

@Retention(RetentionPolicy.RUNTIME)
@Girl
@interface Lucy {


    @AliasFor(annotation = Girl.class, attribute = "girlName")
    String lucyName() default "lucyName";

    @AliasFor(annotation = Girl.class, attribute = "girlAge")
    String lucyAge() default "lucyAge";

}


@Retention(RetentionPolicy.RUNTIME)
@Girl
@interface Ketty {


    @AliasFor(annotation = Girl.class, attribute = "girlName")
    String kettyName() default "kettyName";

    @AliasFor(annotation = Girl.class, attribute = "girlAge")
    String kettyAge() default "kettyAge";

}


@Retention(RetentionPolicy.RUNTIME)
@Man
@interface Boy {

    @AliasFor(attribute = "name", annotation = Man.class)
    String boyName() default "boyName";

    @AliasFor(attribute = "age", annotation = Man.class)
    String boyAge() default "boyAge";

}

@Retention(RetentionPolicy.RUNTIME)
@Man
@interface Girl {

    @AliasFor(attribute = "name", annotation = Man.class)
    String girlName() default "girlName";

    @AliasFor(attribute = "age", annotation = Man.class)
    String girlAge() default "girlName";

}


@Retention(RetentionPolicy.RUNTIME)
@interface Man {

    // @AliasFor(attribute = "age")
    String name() default "man-name";


    //@AliasFor(attribute = "name")
    String age() default "man-age";

}



